/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractCommandController;
import model.Usuario;
import java.util.List;
import service.UsuarioService;
import service.ViajeService;
import org.apache.log4j.*;
import org.apache.log4j.xml.DOMConfigurator;

/**
 *
 * @author MIS DOCUMENTOS
 */
public class MiPerfil extends AbstractCommandController {

    private UsuarioService usuarioService;
    private ViajeService viajeService;
    private static Logger loggers = null;

    public void setViajeService(ViajeService viajeService) {
        this.viajeService = viajeService;
    }

    public void setUsuarioService(UsuarioService usuarioService) {
        this.usuarioService = usuarioService;
    }

    public MiPerfil() {
        this.setCommandClass(Usuario.class);
    }

    @Override
    protected ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object form, BindException errors) throws Exception {
        Map model = new HashMap();

        Usuario user1;

        user1 = (Usuario) usuarioService.getUsuario(Long.parseLong(request.getParameter("ux")));
        List Viajes;
        Viajes = viajeService.listdeMisViajes(user1.getIdUsuario());
        model.put("viaje", Viajes);

        request.getSession().setAttribute("usuarioList", null);
        model.put("title", "MODIFICAR DATOS");
        model.put("usuario", user1);
        return new ModelAndView("perfilUsuario", model);



    }
}
